package com.servlet;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.db.DB;
import com.model.User;

public class MainServlet extends HttpServlet {
	public void doGet(HttpServletRequest requst,HttpServletResponse response) throws IOException{
		requst.setCharacterEncoding("gb123");
		
		response.setContentType("gb123");
		String username=requst.getParameter("username");
		String pwd=requst.getParameter("pwd");
		DB db=new DB();
		HttpSession session=requst.getSession();
		User user=(User) session.getAttribute("user");
		if(user==null){
			user=db.checkUser(username, pwd);
		}
		
		session.setAttribute("user", user);
		if(user!=null){
			ArrayList al=db.findLyInfo();
			session.setAttribute("al", al);
			response.sendRedirect("main.jsp");
		}
		else{
			response.sendRedirect("login.jsp");
		}
		
	}
	public void doPost(HttpServletRequest requst,HttpServletResponse response){
		try {
			doGet(requst,response);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
